package cn.tedu.demo1.cn.tedu;

import cn.tedu.demo1.DBUtiles.DBUtils;
import cn.tedu.demo1.entity.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.PreparedStatement;

@RestController
public class UserController {
    @RequestMapping(path = "/reg",produces = "text/html;charset=utf-8")
    public String reg(User user){
        try(Connection connection = DBUtils.getConn()) {
            String sql = "insert into user values(null,?,?)";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,user.getUsername());
            preparedStatement.setString(2,user.getPassword());
            preparedStatement.executeUpdate();//执行sql语句

        } catch (Exception e) {
            e.printStackTrace();
        }

        return "注册成功!";

    }

}
